<?php
//$Id: view.php 9 2009-04-26 06:35:12Z bole.Chen $
uses('template');

class View extends Template {

    function __construct($data=null) {
        $this->path = VIEWS;
        if ($data) $this->set_vars($data);
    }

    function display($tplfile, $return=false, $cache=false) {
        $html = ob_get_contents();
        ob_end_clean();

        $tplfile = str_replace(array('/','\\'), DS, $tplfile);
        if (!file_exists($this->path.$tplfile)) die('<b>miss view file:</b> '.$this->path.$tplfile);
        $content = $this->fetch($tplfile);
        if ($return) return $html.$content;

        header("Content-type: text/html;charset=utf-8");
        header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
        //header("Expires: " .gmdate ("D, d M Y H:i:s", time() + 3600 * 1). " GMT");
        //header("Cache-control: max-age=3600");

        if ($cache) {
            header("Cache-control: must-revalidate, max-age=$cache");
            header("Pragma: public", true);
        } else
            header("Cache-control: must-revalidate");

        header("Date: " . gmdate("D, d M Y H:i:s") . " GMT");
        header("ETag: ".md5($html.$content));
        header("Content-Length: ".strlen($html.$content));
        //ob_start('ob_gzhandler');
        ob_start();
        echo $html.$content;
    }
}
?>
